#Makefile for sphinx_http_proxy

EVENT_H   = ../../local/libevent/include
EVENT_LIB = ../../local/libevent/lib

CC	= gcc
CXX=g++

#C_FLAGS += -g -Wall -O0
C_FLAGS += -g -O0
LIB_FLAGS = -lpthread -levent -levent_pthreads
LIB = -L$(EVENT_LIB)
INC = -I$(EVENT_H)

SUBDIR =src log json libsphinxclient libthreadpool 

TOPSRC    := $(wildcard *.c) $(wildcard *.cpp)
TOPOBJ     = $(TOPSRC:%.c=%.o) $(TOPSRC:%.cpp=%.o)
SUBSRC_C   = $(shell find $(SUBDIR) -name '*.c')
SUBSRC_CPP = $(shell find $(SUBDIR) -name '*.cpp')
SUBSRC     = $(SUBSRC_C) $(SUBSRC_CPP)
SUBOBJ_C   = $(SUBSRC_C:%.c=%.o)
SUBOBJ_CPP = $(SUBSRC_CPP:%.cpp=%.o)
SUBOBJ     = $(SUBOBJ_C) $(SUBOBJ_CPP)

TARGET     = sphinx_http_proxy_c

all: INFO $(TARGET)

INFO: 
	@echo "TOPSRC"
	@echo $(TOPSRC)
	@echo "TOPOBJ"
	@echo $(TOPOBJ)
	@echo "SUBSRC"
	@echo $(SUBSRC)
	@echo "SUBOBJ"
	@echo $(SUBOBJ)

$(TARGET):$(TOPOBJ) $(SUBOBJ)
	$(CXX) $(C_FLAGS) $(LIB_FLAGS) $(LIB) -o $@ $^
	ctags -R
.c.o:
	@echo $(@D)/$(<F) " -> " $(@D)/$(@F)
	$(CC) $(C_FLAGS) $(INC) -c $(@D)/$(<F) -o $(@D)/$(@F)

.cpp.o:
	@echo $(@D)/$(<F) " -> " $(@D)/$(@F)
	$(CXX) $(C_FLAGS) $(INC) -c $(@D)/$(<F) -o $(@D)/$(@F)

clean:
	rm -f $(TARGET) $(TOPOBJ) $(SUBOBJ)

